<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        {{msg}}
    </div>
    <script type="text/javascript" src="js/vue.js"></script>
    <script type="text/javascript" src="js/axios.js"></script>
    <script>
        const url =
            "https://www.baidu.com/home/other/data/weatherInfo?city=%E6%B7%B1%E5%9C%B3&indextype=manht&_req_seqid=0xef09a5ce0006f24d&asyn=1&t=1590655348911&sid=31725_1421_31670_21122_31594_31606_31270_31464_30823_26350"
        var vm = new Vue({
            el: '#app',
            data: {
                msg: "hello vue"
            },
            mounted() {
                //请求拦截器
                axios.interceptors.request.use((config) => {
                    console.log('config.url =' + config.url);
                    config.headers.token = "axios"
                    return config
                }, (error) => {

                })
                //响应拦截器
                axios.interceptors.response.use((res) => {
                    return res.data
                }, (error) => {

                })
                axios.get(url).then((ret) => { // ret.data是实际返回的数据
                    // console.log(ret.data.data.weather);
                    // console.log(ret.data.data.weather.setting.city);
                    //响应拦截器处理了res， 可以去掉data
                    console.log(ret.data.weather);
                    console.log(ret.data.weather.setting.city);
                })
            },
        })
    </script>
</body>

</html>